<template>
	<view class="content">
		<view class="logo"></view>
		<form @submit="formSubmit">
		<view class="form">
			<view class="label">
				<text>账号</text>
				<input type="text" value="" placeholder="请输入手机号" placeholder-class="s" v-model="username"/>
			</view>
			<view class="label">
				<text>密码</text>
				<input type="password" value="" password="true" placeholder="请输入登录密码" placeholder-class="s" v-model="password" />
			</view>
			<navigator url="./phone_login"><text class="kj">手机快捷登录</text></navigator>
			<button type="primary" form-type="submit" class="button">立即登录</button>
			<view class="link">
				<navigator url="./reset_password"><text>忘记密码</text></navigator>
				<navigator url="./register"><text>注册账号</text></navigator>
			</view>
		</view>
		</form>
<!-- 		<view class="footer_link">
			<text class="iconfont icon-wxtb"></text>
			<text class="iconfont icon-qq-copy"></text>
			<text class="iconfont icon-wbtb"></text>
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username:'',
				password:'',
			}
		},
		onLoad() {
		},
		methods: {
			formSubmit:function(e){
				let self = this;
				let data = {
					username:self.username,
					password:self.password,
				}
				let api_url = self.api_url;				
				uni.request({
					url:api_url+'/api/Login/index',
					data: data,
					dataType: 'json',
					method: 'POST',
					success: (res) => {
						let result = res.data;
						let data = result.data;
						if(result.code == 1 && data.user_token != undefined){
							let user_info = data.user_info;
							let user_token = data.user_token;
							uni.setStorageSync('user_token',user_token);
							uni.setStorageSync('user_info',user_info);
							let pages = getCurrentPages();
							if(pages.length > 1){
								uni.navigateBack();
							}else{
								uni.redirectTo({
									url:'/pages/index/index'
								})
							}
									
						}else{
							let msg = result.msg;
							console.log(result);
							self.showError(msg);
						}
						
					},
					fail: (res) => {
						console.log(res);
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	view,
	text,
	input,
	textarea {
		box-sizing: border-box;
	}
	page{
		background: #fff;
	}
	.content{
		overflow: hidden;
		width: 100%;
		padding: 146rpx 92rpx 0 92rpx;
		position: relative;
		.logo{
			width: 165rpx;
			background: #153B33;
			height: 165rpx;
			margin: 0 auto;
			border-radius: 38rpx;
		}
		.link{
			overflow: hidden;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 42rpx;
			padding: 0 20rpx;
			text{
				font-size: 23rpx;
				color: #2e2e2e;
			}
		}
		.footer_link{
			overflow: hidden;
			display: flex;
			align-items: center;
			position: fixed;
			left: 0;
			bottom: 100rpx;
			width: 100%;
			justify-content: center;
			text{
				font-size: 80rpx;
				color: #7A7A7C;
				margin: 0 50rpx;
			}
			
		}
		.form{
			overflow: hidden;
			margin-top: 112rpx;
			.kj{
				display: block;
				width: 100%;
				text-align: right;
				font-size: 22rpx;
				color: #2E2E2E;
				line-height: 31rpx;
			}
			.button{
				width: 100%;
				height: 83rpx;
				background: #153B33;
				border-radius: 42rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 28rpx;
				color: #fff;
				margin-top: 78rpx;
			}
			.label{
				overflow: hidden;
				margin-bottom: 30rpx;
				width: 100%;
				text{
					display: block;
					font-size: 25rpx;
					color: #000000;
				}
				input{
					width: 100%;
					height: 80rpx;
					border: none;
					border-bottom: 1px solid #f4f4f4;
					background: none;
					font-size: 28rpx;
					color: #000000;
				}
				.s{
					font-size: 28rpx;
					color: #C5C5C5;
				}
			}
		}
	}
</style>
